package org.example.struct.array;

import java.util.Arrays;

/**
 * @author liyishan
 * @date 2023/8/23 09:28
 * @apiNote
 */

public class Test01464MaxProduct {
    public static void main(String[] args) {
        int[] nums = {3,4,5,2};
        int count = test(nums);
        System.out.println(count);
    }

    public static int test(int[] nums) {
        int n = nums.length;
        int max = Integer.MIN_VALUE;
        for(int i = 0; i < n; i++){
            for(int j = i+1;j<n;j++){
                max = Math.max(max,(nums[i]-1)*(nums[j]-1));
            }
        }
        return max;
    }

    public static int test1(int[] nums) {
        Arrays.sort(nums);
        return (nums[nums.length-1]-1)*(nums[nums.length-2]-1);
    }

    public static int test2(int[] nums) {
        int a = nums[0],b = nums[1];
        if(a<b){
            int temp = a;
            a=b;
            b=temp;
        }
        for(int i = 2;i<nums.length;i++){
            if(nums[i]>a){
                b=a;
                a=nums[i];
            }else if(nums[i]>b){
                b=nums[i];
            }
        }
        return (a-1)*(b-1);
    }
}
